import os
import sys

import numpy as np
from pymatgen.core.structure import Structure


assert len(sys.argv) == 6
openmx_path = sys.argv[1]
openmx_overlap_path = sys.argv[2]
pot_path = sys.argv[3]
python_interpreter = sys.argv[4]
julia_interpreter = sys.argv[5]
os.makedirs('../example', exist_ok=True)

os.makedirs('../example/1_DFT_calculation', exist_ok=True)
save_str = """Bi4                                     
   1.00000000000000     
     4.3664811210045835   -0.0000000000000001    0.0000000000000000
    -2.1832405605022918    3.7814838764134606    0.0000000000000000
     0.0000000000000000    0.0000000000000000   19.0000000000000000
   Bi
     4
Direct
  0.3333330000000032  0.6666669999999968  0.2730790361311790
  0.0000000000000000  0.0000000000000000  0.3637838957355797
  0.3333330000000032  0.6666669999999968  0.5324481042644251
  0.0000000000000000  0.0000000000000000  0.6231529638688187
"""
with open('../example/1_DFT_calculation/POSCAR', 'w') as save_f:
    save_f.write(save_str)
os.makedirs('../example/work_dir/dataset/raw', exist_ok=True)

np.random.seed(42)
stru_unit = Structure.from_file('../example/1_DFT_calculation/POSCAR')
shifts_a, shifts_b = np.linspace(0, 1, 25)[0:-1], np.linspace(0, 1, 25)[:-1]
shift_list = [[shift_a, shift_b] for shift_a in shifts_a for shift_b in shifts_b]
for shift_index, shift in enumerate(shift_list):
    unit_frac_coords = stru_unit.frac_coords
    unit_frac_coords[2:, 0] += shift[0]
    unit_frac_coords[2:, 1] += shift[1]
    stru_shift = Structure(
        stru_unit.lattice,
        stru_unit.species,
        unit_frac_coords,
        coords_are_cartesian=False,
        to_unit_cell=True)
    stru_shift.make_supercell([[3, 0, 0], [0, 3, 0], [0, 0, 1]])
    super_cart_coords = stru_shift.cart_coords
    pert_x = (np.random.rand(len(stru_shift), 1) - 0.5) * (0.1 * 2)
    pert_y = (np.random.rand(len(stru_shift), 1) - 0.5) * (0.1 * 2)
    pert_z = (np.random.rand(len(stru_shift), 1) - 0.5) * (0.1 * 2)
    super_cart_coords += np.concatenate([pert_x, pert_y, pert_z], axis=-1)
    stru_shift_pert = Structure(
        stru_shift.lattice,
        stru_shift.species,
        super_cart_coords,
        coords_are_cartesian=True,
        to_unit_cell=True)
    frac_coords = stru_shift_pert.frac_coords
    frac_coords_str = ''
    for i in range(len(stru_shift)):
        frac_coords_str += f' {i + 1} Bi {frac_coords[i, 0]} {frac_coords[i, 1]} {frac_coords[i, 2]} 7.5  7.5  0.0  0.0  0.0  0.0  0  '
        if i != len(stru_shift) - 1:
            frac_coords_str += '\n'

    save_str = f"""System.Name                       openmx
DATA.PATH                         {pot_path}
HS.fileout                        on

Species.Number                    1
<Definition.of.Atomic.Species
  Bi   Bi8.0-s3p2d2   Bi_PBE19
Definition.of.Atomic.Species>
Atoms.Number                      36
Atoms.SpeciesAndCoordinates.Unit  FRAC
<Atoms.SpeciesAndCoordinates
{frac_coords_str}
Atoms.SpeciesAndCoordinates>

Atoms.UnitVectors.Unit            Ang
<Atoms.UnitVectors
  13.0994433630137515 -0.0000000000000003 0.0000000000000000
  -6.5497216815068757 11.3444516292403819 0.0000000000000000
  0.0000000000000000 0.0000000000000000 19.0000000000000000
Atoms.UnitVectors>

scf.XcType                        GGA-PBE   # LDA/LSDA-CA/LSDA-PW/GGA-PBE
scf.ElectronicTemperature         300.0     # default=300 (K) SIGMA in VASP
scf.energycutoff                  300       # default=150 (Ry = 13.6eV)
scf.maxIter                       2000
scf.EigenvalueSolver              Band      # DC/DC-LNO/Krylov/ON2/Cluster/Band
scf.Kgrid                         5  5  1
scf.criterion                     4e-08     # (Hartree = 27.21eV)
scf.partialCoreCorrection         on

scf.SpinPolarization              nc
scf.SpinOrbit.Coupling            on

scf.Mixing.Type                   RMM-DIISK
scf.Init.Mixing.Weight            0.3
scf.Mixing.History                30
scf.Mixing.StartPulay             6
scf.Mixing.EveryPulay             1

1DFFT.EnergyCutoff                3600
1DFFT.NumGridK                    900
1DFFT.NumGridR                    900

scf.ProExpn.VNA                   off

MD.Type                           Nomd      # Nomd (SCF) / NVT_NH (MD)
### END ###
    """
    os.makedirs(f'../example/work_dir/dataset/raw/{shift_index}', exist_ok=True)
    with open(f'../example/work_dir/dataset/raw/{shift_index}/openmx_in.dat', 'w') as save_f:
        save_f.write(save_str)
    stru_shift_pert.to(fmt='poscar', filename=f'../example/work_dir/dataset/raw/{shift_index}/POSCAR')

save_str = """cd ../work_dir/dataset/raw/0
for i in {0..575}; do

cd ../$i
mpirun -np 64 %s openmx_in.dat > openmx.std
cat openmx.out >> openmx.scfout
rm -r openmx_rst *.cube

done
""" % openmx_path
with open('../example/1_DFT_calculation/run.sh', 'w') as save_f:
    save_f.write(save_str)

os.makedirs('../example/2_preprocess', exist_ok=True)
save_str = f"""[basic]
raw_dir = {os.path.abspath("../example/work_dir/dataset/raw")}
processed_dir = {os.path.abspath("../example/work_dir/dataset/processed")}
target = hamiltonian
interface = openmx

[interpreter]
python_interpreter = {python_interpreter}
julia_interpreter = {julia_interpreter}

[graph]
radius = 9.0
create_from_DFT = True
"""
with open('../example/2_preprocess/preprocess.ini', 'w') as save_f:
    save_f.write(save_str)
save_str = """deeph-preprocess --config preprocess.ini
"""
with open('../example/2_preprocess/run.sh', 'w') as save_f:
    save_f.write(save_str)

os.makedirs('../example/3_train', exist_ok=True)
save_str = """[basic]
graph_dir = %s
save_dir = %s
raw_dir = %s
dataset_name = Bi_soc
device = cuda:0
num_threads = 64
save_to_time_folder = False
save_csv = False
seed = 42
orbital = [{"83 83": [0, 0]}, {"83 83": [0, 1]}, {"83 83": [0, 2]}, {"83 83": [0, 3]}, {"83 83": [0, 4]}, {"83 83": [0, 5]}, {"83 83": [0, 6]}, {"83 83": [0, 7]}, {"83 83": [0, 8]}, {"83 83": [0, 9]}, {"83 83": [0, 10]}, {"83 83": [0, 11]}, {"83 83": [0, 12]}, {"83 83": [0, 13]}, {"83 83": [0, 14]}, {"83 83": [0, 15]}, {"83 83": [0, 16]}, {"83 83": [0, 17]}, {"83 83": [0, 18]}, {"83 83": [1, 0]}, {"83 83": [1, 1]}, {"83 83": [1, 2]}, {"83 83": [1, 3]}, {"83 83": [1, 4]}, {"83 83": [1, 5]}, {"83 83": [1, 6]}, {"83 83": [1, 7]}, {"83 83": [1, 8]}, {"83 83": [1, 9]}, {"83 83": [1, 10]}, {"83 83": [1, 11]}, {"83 83": [1, 12]}, {"83 83": [1, 13]}, {"83 83": [1, 14]}, {"83 83": [1, 15]}, {"83 83": [1, 16]}, {"83 83": [1, 17]}, {"83 83": [1, 18]}, {"83 83": [2, 0]}, {"83 83": [2, 1]}, {"83 83": [2, 2]}, {"83 83": [2, 3]}, {"83 83": [2, 4]}, {"83 83": [2, 5]}, {"83 83": [2, 6]}, {"83 83": [2, 7]}, {"83 83": [2, 8]}, {"83 83": [2, 9]}, {"83 83": [2, 10]}, {"83 83": [2, 11]}, {"83 83": [2, 12]}, {"83 83": [2, 13]}, {"83 83": [2, 14]}, {"83 83": [2, 15]}, {"83 83": [2, 16]}, {"83 83": [2, 17]}, {"83 83": [2, 18]}, {"83 83": [3, 0]}, {"83 83": [3, 1]}, {"83 83": [3, 2]}, {"83 83": [3, 3]}, {"83 83": [3, 4]}, {"83 83": [3, 5]}, {"83 83": [3, 6]}, {"83 83": [3, 7]}, {"83 83": [3, 8]}, {"83 83": [3, 9]}, {"83 83": [3, 10]}, {"83 83": [3, 11]}, {"83 83": [3, 12]}, {"83 83": [3, 13]}, {"83 83": [3, 14]}, {"83 83": [3, 15]}, {"83 83": [3, 16]}, {"83 83": [3, 17]}, {"83 83": [3, 18]}, {"83 83": [4, 0]}, {"83 83": [4, 1]}, {"83 83": [4, 2]}, {"83 83": [4, 3]}, {"83 83": [4, 4]}, {"83 83": [4, 5]}, {"83 83": [4, 6]}, {"83 83": [4, 7]}, {"83 83": [4, 8]}, {"83 83": [4, 9]}, {"83 83": [4, 10]}, {"83 83": [4, 11]}, {"83 83": [4, 12]}, {"83 83": [4, 13]}, {"83 83": [4, 14]}, {"83 83": [4, 15]}, {"83 83": [4, 16]}, {"83 83": [4, 17]}, {"83 83": [4, 18]}, {"83 83": [5, 0]}, {"83 83": [5, 1]}, {"83 83": [5, 2]}, {"83 83": [5, 3]}, {"83 83": [5, 4]}, {"83 83": [5, 5]}, {"83 83": [5, 6]}, {"83 83": [5, 7]}, {"83 83": [5, 8]}, {"83 83": [5, 9]}, {"83 83": [5, 10]}, {"83 83": [5, 11]}, {"83 83": [5, 12]}, {"83 83": [5, 13]}, {"83 83": [5, 14]}, {"83 83": [5, 15]}, {"83 83": [5, 16]}, {"83 83": [5, 17]}, {"83 83": [5, 18]}, {"83 83": [6, 0]}, {"83 83": [6, 1]}, {"83 83": [6, 2]}, {"83 83": [6, 3]}, {"83 83": [6, 4]}, {"83 83": [6, 5]}, {"83 83": [6, 6]}, {"83 83": [6, 7]}, {"83 83": [6, 8]}, {"83 83": [6, 9]}, {"83 83": [6, 10]}, {"83 83": [6, 11]}, {"83 83": [6, 12]}, {"83 83": [6, 13]}, {"83 83": [6, 14]}, {"83 83": [6, 15]}, {"83 83": [6, 16]}, {"83 83": [6, 17]}, {"83 83": [6, 18]}, {"83 83": [7, 0]}, {"83 83": [7, 1]}, {"83 83": [7, 2]}, {"83 83": [7, 3]}, {"83 83": [7, 4]}, {"83 83": [7, 5]}, {"83 83": [7, 6]}, {"83 83": [7, 7]}, {"83 83": [7, 8]}, {"83 83": [7, 9]}, {"83 83": [7, 10]}, {"83 83": [7, 11]}, {"83 83": [7, 12]}, {"83 83": [7, 13]}, {"83 83": [7, 14]}, {"83 83": [7, 15]}, {"83 83": [7, 16]}, {"83 83": [7, 17]}, {"83 83": [7, 18]}, {"83 83": [8, 0]}, {"83 83": [8, 1]}, {"83 83": [8, 2]}, {"83 83": [8, 3]}, {"83 83": [8, 4]}, {"83 83": [8, 5]}, {"83 83": [8, 6]}, {"83 83": [8, 7]}, {"83 83": [8, 8]}, {"83 83": [8, 9]}, {"83 83": [8, 10]}, {"83 83": [8, 11]}, {"83 83": [8, 12]}, {"83 83": [8, 13]}, {"83 83": [8, 14]}, {"83 83": [8, 15]}, {"83 83": [8, 16]}, {"83 83": [8, 17]}, {"83 83": [8, 18]}, {"83 83": [9, 0]}, {"83 83": [9, 1]}, {"83 83": [9, 2]}, {"83 83": [9, 3]}, {"83 83": [9, 4]}, {"83 83": [9, 5]}, {"83 83": [9, 6]}, {"83 83": [9, 7]}, {"83 83": [9, 8]}, {"83 83": [9, 9]}, {"83 83": [9, 10]}, {"83 83": [9, 11]}, {"83 83": [9, 12]}, {"83 83": [9, 13]}, {"83 83": [9, 14]}, {"83 83": [9, 15]}, {"83 83": [9, 16]}, {"83 83": [9, 17]}, {"83 83": [9, 18]}, {"83 83": [10, 0]}, {"83 83": [10, 1]}, {"83 83": [10, 2]}, {"83 83": [10, 3]}, {"83 83": [10, 4]}, {"83 83": [10, 5]}, {"83 83": [10, 6]}, {"83 83": [10, 7]}, {"83 83": [10, 8]}, {"83 83": [10, 9]}, {"83 83": [10, 10]}, {"83 83": [10, 11]}, {"83 83": [10, 12]}, {"83 83": [10, 13]}, {"83 83": [10, 14]}, {"83 83": [10, 15]}, {"83 83": [10, 16]}, {"83 83": [10, 17]}, {"83 83": [10, 18]}, {"83 83": [11, 0]}, {"83 83": [11, 1]}, {"83 83": [11, 2]}, {"83 83": [11, 3]}, {"83 83": [11, 4]}, {"83 83": [11, 5]}, {"83 83": [11, 6]}, {"83 83": [11, 7]}, {"83 83": [11, 8]}, {"83 83": [11, 9]}, {"83 83": [11, 10]}, {"83 83": [11, 11]}, {"83 83": [11, 12]}, {"83 83": [11, 13]}, {"83 83": [11, 14]}, {"83 83": [11, 15]}, {"83 83": [11, 16]}, {"83 83": [11, 17]}, {"83 83": [11, 18]}, {"83 83": [12, 0]}, {"83 83": [12, 1]}, {"83 83": [12, 2]}, {"83 83": [12, 3]}, {"83 83": [12, 4]}, {"83 83": [12, 5]}, {"83 83": [12, 6]}, {"83 83": [12, 7]}, {"83 83": [12, 8]}, {"83 83": [12, 9]}, {"83 83": [12, 10]}, {"83 83": [12, 11]}, {"83 83": [12, 12]}, {"83 83": [12, 13]}, {"83 83": [12, 14]}, {"83 83": [12, 15]}, {"83 83": [12, 16]}, {"83 83": [12, 17]}, {"83 83": [12, 18]}, {"83 83": [13, 0]}, {"83 83": [13, 1]}, {"83 83": [13, 2]}, {"83 83": [13, 3]}, {"83 83": [13, 4]}, {"83 83": [13, 5]}, {"83 83": [13, 6]}, {"83 83": [13, 7]}, {"83 83": [13, 8]}, {"83 83": [13, 9]}, {"83 83": [13, 10]}, {"83 83": [13, 11]}, {"83 83": [13, 12]}, {"83 83": [13, 13]}, {"83 83": [13, 14]}, {"83 83": [13, 15]}, {"83 83": [13, 16]}, {"83 83": [13, 17]}, {"83 83": [13, 18]}, {"83 83": [14, 0]}, {"83 83": [14, 1]}, {"83 83": [14, 2]}, {"83 83": [14, 3]}, {"83 83": [14, 4]}, {"83 83": [14, 5]}, {"83 83": [14, 6]}, {"83 83": [14, 7]}, {"83 83": [14, 8]}, {"83 83": [14, 9]}, {"83 83": [14, 10]}, {"83 83": [14, 11]}, {"83 83": [14, 12]}, {"83 83": [14, 13]}, {"83 83": [14, 14]}, {"83 83": [14, 15]}, {"83 83": [14, 16]}, {"83 83": [14, 17]}, {"83 83": [14, 18]}, {"83 83": [15, 0]}, {"83 83": [15, 1]}, {"83 83": [15, 2]}, {"83 83": [15, 3]}, {"83 83": [15, 4]}, {"83 83": [15, 5]}, {"83 83": [15, 6]}, {"83 83": [15, 7]}, {"83 83": [15, 8]}, {"83 83": [15, 9]}, {"83 83": [15, 10]}, {"83 83": [15, 11]}, {"83 83": [15, 12]}, {"83 83": [15, 13]}, {"83 83": [15, 14]}, {"83 83": [15, 15]}, {"83 83": [15, 16]}, {"83 83": [15, 17]}, {"83 83": [15, 18]}, {"83 83": [16, 0]}, {"83 83": [16, 1]}, {"83 83": [16, 2]}, {"83 83": [16, 3]}, {"83 83": [16, 4]}, {"83 83": [16, 5]}, {"83 83": [16, 6]}, {"83 83": [16, 7]}, {"83 83": [16, 8]}, {"83 83": [16, 9]}, {"83 83": [16, 10]}, {"83 83": [16, 11]}, {"83 83": [16, 12]}, {"83 83": [16, 13]}, {"83 83": [16, 14]}, {"83 83": [16, 15]}, {"83 83": [16, 16]}, {"83 83": [16, 17]}, {"83 83": [16, 18]}, {"83 83": [17, 0]}, {"83 83": [17, 1]}, {"83 83": [17, 2]}, {"83 83": [17, 3]}, {"83 83": [17, 4]}, {"83 83": [17, 5]}, {"83 83": [17, 6]}, {"83 83": [17, 7]}, {"83 83": [17, 8]}, {"83 83": [17, 9]}, {"83 83": [17, 10]}, {"83 83": [17, 11]}, {"83 83": [17, 12]}, {"83 83": [17, 13]}, {"83 83": [17, 14]}, {"83 83": [17, 15]}, {"83 83": [17, 16]}, {"83 83": [17, 17]}, {"83 83": [17, 18]}, {"83 83": [18, 0]}, {"83 83": [18, 1]}, {"83 83": [18, 2]}, {"83 83": [18, 3]}, {"83 83": [18, 4]}, {"83 83": [18, 5]}, {"83 83": [18, 6]}, {"83 83": [18, 7]}, {"83 83": [18, 8]}, {"83 83": [18, 9]}, {"83 83": [18, 10]}, {"83 83": [18, 11]}, {"83 83": [18, 12]}, {"83 83": [18, 13]}, {"83 83": [18, 14]}, {"83 83": [18, 15]}, {"83 83": [18, 16]}, {"83 83": [18, 17]}, {"83 83": [18, 18]}]

[graph]
create_from_DFT = True

[train]
epochs = 10000
train_ratio = 0.6
val_ratio = 0.2
test_ratio = 0.2
revert_then_decay = True
revert_decay_epoch = [250, 2500]
revert_decay_gamma = [0.2, 0.5]

[hyperparameter]
batch_size = 1
learning_rate = 0.001

[network]
gauss_stop = 8.5
""" % (os.path.abspath("../example/work_dir/dataset/graph"), os.path.abspath("../example/work_dir/trained_model"), os.path.abspath("../example/work_dir/dataset/processed"))
with open('../example/3_train/train.ini', 'w') as save_f:
    save_f.write(save_str)
save_str = """deeph-train --config train.ini
"""
with open('../example/3_train/run.sh', 'w') as save_f:
    save_f.write(save_str)

os.makedirs('../example/4_compute_overlap', exist_ok=True)
os.makedirs('../example/work_dir/olp/5_4', exist_ok=True)
save_str = """Bi244
1.0
28.382129 18.907420 0.000000
-2.183236 34.033356 0.000000
0.000000 0.000000 19.000000
Bi
244
direct
0.218579 0.841530 0.273079 Bi
0.300546 0.907104 0.273079 Bi
0.382514 0.972678 0.273079 Bi
0.202186 0.628415 0.273079 Bi
0.284153 0.693989 0.273079 Bi
0.366120 0.759563 0.273079 Bi
0.448087 0.825137 0.273079 Bi
0.530055 0.890710 0.273079 Bi
0.612022 0.956284 0.273079 Bi
0.185792 0.415301 0.273079 Bi
0.267759 0.480874 0.273079 Bi
0.349727 0.546448 0.273079 Bi
0.431694 0.612022 0.273079 Bi
0.513661 0.677596 0.273079 Bi
0.595628 0.743169 0.273079 Bi
0.677596 0.808743 0.273079 Bi
0.759563 0.874317 0.273079 Bi
0.841530 0.939891 0.273079 Bi
0.169399 0.202186 0.273079 Bi
0.251366 0.267760 0.273079 Bi
0.333333 0.333333 0.273079 Bi
0.415300 0.398907 0.273079 Bi
0.497268 0.464481 0.273079 Bi
0.579235 0.530055 0.273079 Bi
0.661202 0.595628 0.273079 Bi
0.743169 0.661202 0.273079 Bi
0.825137 0.726776 0.273079 Bi
0.907104 0.792350 0.273079 Bi
0.989071 0.857924 0.273079 Bi
0.071038 0.923497 0.273079 Bi
0.153005 0.989071 0.273079 Bi
0.234973 0.054645 0.273079 Bi
0.316940 0.120219 0.273079 Bi
0.398907 0.185792 0.273079 Bi
0.480874 0.251366 0.273079 Bi
0.562841 0.316940 0.273079 Bi
0.644809 0.382514 0.273079 Bi
0.726776 0.448088 0.273079 Bi
0.808743 0.513661 0.273079 Bi
0.890710 0.579235 0.273079 Bi
0.972678 0.644809 0.273079 Bi
0.054645 0.710383 0.273079 Bi
0.136612 0.775956 0.273079 Bi
0.464481 0.038251 0.273079 Bi
0.546448 0.103825 0.273079 Bi
0.628415 0.169399 0.273079 Bi
0.710382 0.234973 0.273079 Bi
0.792350 0.300547 0.273079 Bi
0.874317 0.366120 0.273079 Bi
0.956284 0.431694 0.273079 Bi
0.038251 0.497268 0.273079 Bi
0.120219 0.562842 0.273079 Bi
0.693989 0.021858 0.273079 Bi
0.775956 0.087432 0.273079 Bi
0.857923 0.153006 0.273079 Bi
0.939891 0.218579 0.273079 Bi
0.021858 0.284153 0.273079 Bi
0.103825 0.349727 0.273079 Bi
0.923497 0.005465 0.273079 Bi
0.005464 0.071038 0.273079 Bi
0.087432 0.136612 0.273079 Bi
0.065574 0.852459 0.363784 Bi
0.147541 0.918033 0.363784 Bi
0.229508 0.983607 0.363784 Bi
0.049180 0.639344 0.363784 Bi
0.131148 0.704918 0.363784 Bi
0.213115 0.770492 0.363784 Bi
0.295082 0.836066 0.363784 Bi
0.377049 0.901639 0.363784 Bi
0.459016 0.967213 0.363784 Bi
0.032787 0.426230 0.363784 Bi
0.114754 0.491803 0.363784 Bi
0.196721 0.557377 0.363784 Bi
0.278689 0.622951 0.363784 Bi
0.360656 0.688525 0.363784 Bi
0.442623 0.754098 0.363784 Bi
0.524590 0.819672 0.363784 Bi
0.606557 0.885246 0.363784 Bi
0.688525 0.950820 0.363784 Bi
0.016393 0.213115 0.363784 Bi
0.098361 0.278689 0.363784 Bi
0.180328 0.344262 0.363784 Bi
0.262295 0.409836 0.363784 Bi
0.344262 0.475410 0.363784 Bi
0.426230 0.540984 0.363784 Bi
0.508197 0.606557 0.363784 Bi
0.590164 0.672131 0.363784 Bi
0.672131 0.737705 0.363784 Bi
0.754098 0.803279 0.363784 Bi
0.836066 0.868852 0.363784 Bi
0.918033 0.934426 0.363784 Bi
0.000000 0.000000 0.363784 Bi
0.081967 0.065574 0.363784 Bi
0.163934 0.131148 0.363784 Bi
0.245902 0.196721 0.363784 Bi
0.327869 0.262295 0.363784 Bi
0.409836 0.327869 0.363784 Bi
0.491803 0.393443 0.363784 Bi
0.573770 0.459016 0.363784 Bi
0.655738 0.524590 0.363784 Bi
0.737705 0.590164 0.363784 Bi
0.819672 0.655738 0.363784 Bi
0.901639 0.721311 0.363784 Bi
0.983607 0.786885 0.363784 Bi
0.311475 0.049180 0.363784 Bi
0.393443 0.114754 0.363784 Bi
0.475410 0.180328 0.363784 Bi
0.557377 0.245902 0.363784 Bi
0.639344 0.311475 0.363784 Bi
0.721311 0.377049 0.363784 Bi
0.803279 0.442623 0.363784 Bi
0.885246 0.508197 0.363784 Bi
0.967213 0.573770 0.363784 Bi
0.540984 0.032787 0.363784 Bi
0.622951 0.098361 0.363784 Bi
0.704918 0.163934 0.363784 Bi
0.786885 0.229508 0.363784 Bi
0.868852 0.295082 0.363784 Bi
0.950820 0.360656 0.363784 Bi
0.770492 0.016393 0.363784 Bi
0.852459 0.081967 0.363784 Bi
0.934426 0.147541 0.363784 Bi
0.158470 0.781421 0.532448 Bi
0.224044 0.863388 0.532448 Bi
0.289617 0.945355 0.532448 Bi
0.174863 0.551913 0.532448 Bi
0.240437 0.633880 0.532448 Bi
0.306011 0.715847 0.532448 Bi
0.371585 0.797814 0.532448 Bi
0.437158 0.879781 0.532448 Bi
0.502732 0.961749 0.532448 Bi
0.191257 0.322404 0.532448 Bi
0.256831 0.404372 0.532448 Bi
0.322404 0.486339 0.532448 Bi
0.387978 0.568306 0.532448 Bi
0.453552 0.650273 0.532448 Bi
0.519126 0.732241 0.532448 Bi
0.584699 0.814208 0.532448 Bi
0.650273 0.896175 0.532448 Bi
0.715847 0.978142 0.532448 Bi
0.142076 0.010929 0.532448 Bi
0.207650 0.092896 0.532448 Bi
0.273224 0.174863 0.532448 Bi
0.338798 0.256831 0.532448 Bi
0.404372 0.338798 0.532448 Bi
0.469945 0.420765 0.532448 Bi
0.535519 0.502732 0.532448 Bi
0.601093 0.584700 0.532448 Bi
0.666667 0.666667 0.532448 Bi
0.732240 0.748634 0.532448 Bi
0.797814 0.830601 0.532448 Bi
0.863388 0.912568 0.532448 Bi
0.928962 0.994536 0.532448 Bi
0.355191 0.027322 0.532448 Bi
0.420765 0.109290 0.532448 Bi
0.486339 0.191257 0.532448 Bi
0.551912 0.273224 0.532448 Bi
0.617486 0.355191 0.532448 Bi
0.683060 0.437159 0.532448 Bi
0.748634 0.519126 0.532448 Bi
0.814208 0.601093 0.532448 Bi
0.879781 0.683060 0.532448 Bi
0.945355 0.765027 0.532448 Bi
0.010929 0.846995 0.532448 Bi
0.076503 0.928962 0.532448 Bi
0.568306 0.043716 0.532448 Bi
0.633880 0.125683 0.532448 Bi
0.699453 0.207650 0.532448 Bi
0.765027 0.289618 0.532448 Bi
0.830601 0.371585 0.532448 Bi
0.896175 0.453552 0.532448 Bi
0.961749 0.535519 0.532448 Bi
0.027322 0.617486 0.532448 Bi
0.092896 0.699454 0.532448 Bi
0.781421 0.060109 0.532448 Bi
0.846994 0.142077 0.532448 Bi
0.912568 0.224044 0.532448 Bi
0.978142 0.306011 0.532448 Bi
0.043716 0.387978 0.532448 Bi
0.109290 0.469945 0.532448 Bi
0.994535 0.076503 0.532448 Bi
0.060109 0.158470 0.532448 Bi
0.125683 0.240437 0.532448 Bi
0.016393 0.770492 0.623153 Bi
0.081967 0.852459 0.623153 Bi
0.147541 0.934426 0.623153 Bi
0.032787 0.540984 0.623153 Bi
0.098361 0.622951 0.623153 Bi
0.163934 0.704918 0.623153 Bi
0.229508 0.786885 0.623153 Bi
0.295082 0.868852 0.623153 Bi
0.360656 0.950820 0.623153 Bi
0.049180 0.311475 0.623153 Bi
0.114754 0.393443 0.623153 Bi
0.180328 0.475410 0.623153 Bi
0.245902 0.557377 0.623153 Bi
0.311475 0.639344 0.623153 Bi
0.377049 0.721311 0.623153 Bi
0.442623 0.803279 0.623153 Bi
0.508197 0.885246 0.623153 Bi
0.573770 0.967213 0.623153 Bi
0.000000 0.000000 0.623153 Bi
0.065574 0.081967 0.623153 Bi
0.131148 0.163934 0.623153 Bi
0.196721 0.245902 0.623153 Bi
0.262295 0.327869 0.623153 Bi
0.327869 0.409836 0.623153 Bi
0.393443 0.491803 0.623153 Bi
0.459016 0.573770 0.623153 Bi
0.524590 0.655738 0.623153 Bi
0.590164 0.737705 0.623153 Bi
0.655738 0.819672 0.623153 Bi
0.721311 0.901639 0.623153 Bi
0.786885 0.983607 0.623153 Bi
0.213115 0.016393 0.623153 Bi
0.278689 0.098361 0.623153 Bi
0.344262 0.180328 0.623153 Bi
0.409836 0.262295 0.623153 Bi
0.475410 0.344262 0.623153 Bi
0.540984 0.426230 0.623153 Bi
0.606557 0.508197 0.623153 Bi
0.672131 0.590164 0.623153 Bi
0.737705 0.672131 0.623153 Bi
0.803279 0.754098 0.623153 Bi
0.868852 0.836066 0.623153 Bi
0.934426 0.918033 0.623153 Bi
0.426230 0.032787 0.623153 Bi
0.491803 0.114754 0.623153 Bi
0.557377 0.196721 0.623153 Bi
0.622951 0.278689 0.623153 Bi
0.688525 0.360656 0.623153 Bi
0.754098 0.442623 0.623153 Bi
0.819672 0.524590 0.623153 Bi
0.885246 0.606557 0.623153 Bi
0.950820 0.688525 0.623153 Bi
0.639344 0.049180 0.623153 Bi
0.704918 0.131148 0.623153 Bi
0.770492 0.213115 0.623153 Bi
0.836066 0.295082 0.623153 Bi
0.901639 0.377049 0.623153 Bi
0.967213 0.459016 0.623153 Bi
0.852459 0.065574 0.623153 Bi
0.918033 0.147541 0.623153 Bi
0.983607 0.229508 0.623153 Bi
"""
with open('../example/work_dir/olp/5_4/POSCAR', 'w') as save_f:
    save_f.write(save_str)
save_str = f"""System.Name                       openmx
DATA.PATH                         {pot_path}
HS.fileout                        on

Species.Number                    1
<Definition.of.Atomic.Species
  Bi   Bi8.0-s3p2d2   Bi_PBE19
Definition.of.Atomic.Species>
Atoms.Number                      244
Atoms.SpeciesAndCoordinates.Unit  FRAC
<Atoms.SpeciesAndCoordinates
  1  Bi    0.2185791600000000  0.8415301300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  2  Bi    0.3005463800000000  0.9071039000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  3  Bi    0.3825135900000000  0.9726776700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  4  Bi    0.2021857200000000  0.6284153800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  5  Bi    0.2841529300000000  0.6939891500000001  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  6  Bi    0.3661201500000000  0.7595629200000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  7  Bi    0.4480873600000000  0.8251366900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  8  Bi    0.5300545700000000  0.8907104600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  9  Bi    0.6120217900000000  0.9562842300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  10  Bi    0.1857922800000000  0.4153006200000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  11  Bi    0.2677594900000000  0.4808743900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  12  Bi    0.3497267000000000  0.5464481600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  13  Bi    0.4316939200000000  0.6120219300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  14  Bi    0.5136611300000000  0.6775957000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  15  Bi    0.5956283400000000  0.7431694800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  16  Bi    0.6775955600000000  0.8087432500000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  17  Bi    0.7595627700000001  0.8743170200000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  18  Bi    0.8415299800000000  0.9398907900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  19  Bi    0.1693988400000000  0.2021858700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  20  Bi    0.2513660500000000  0.2677596400000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  21  Bi    0.3333332600000000  0.3333334100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  22  Bi    0.4153004800000000  0.3989071800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  23  Bi    0.4972676900000000  0.4644809500000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  24  Bi    0.5792349000000000  0.5300547200000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  25  Bi    0.6612021100000000  0.5956284900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  26  Bi    0.7431693300000000  0.6612022600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  27  Bi    0.8251365400000000  0.7267760300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  28  Bi    0.9071037500000000  0.7923498000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  29  Bi    0.9890709700000000  0.8579235700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  30  Bi    0.0710381800000000  0.9234973400000001  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  31  Bi    0.1530053900000000  0.9890711100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  32  Bi    0.2349726100000000  0.0546448900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  33  Bi    0.3169398200000000  0.1202186600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  34  Bi    0.3989070300000000  0.1857924300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  35  Bi    0.4808742500000000  0.2513662000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  36  Bi    0.5628414600000000  0.3169399700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  37  Bi    0.6448086700000000  0.3825137400000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  38  Bi    0.7267758900000000  0.4480875100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  39  Bi    0.8087431000000000  0.5136612800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  40  Bi    0.8907103100000000  0.5792350500000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  41  Bi    0.9726775200000000  0.6448088199999999  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  42  Bi    0.0546447400000001  0.7103825900000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  43  Bi    0.1366119500000000  0.7759563600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  44  Bi    0.4644808000000000  0.0382514400000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  45  Bi    0.5464480200000000  0.1038252100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  46  Bi    0.6284152300000000  0.1693989800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  47  Bi    0.7103824399999999  0.2349727500000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  48  Bi    0.7923496600000000  0.3005465200000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  49  Bi    0.8743168700000000  0.3661203000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  50  Bi    0.9562840800000000  0.4316940700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  51  Bi    0.0382513000000000  0.4972678400000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  52  Bi    0.1202185099999999  0.5628416100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  53  Bi    0.6939890000000000  0.0218580000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  54  Bi    0.7759562100000000  0.0874317700000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  55  Bi    0.8579234300000000  0.1530055400000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  56  Bi    0.9398906400000000  0.2185793100000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  57  Bi    0.0218578500000000  0.2841530800000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  58  Bi    0.1038250700000001  0.3497268500000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  59  Bi    0.9234972000000000  0.0054645600000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  60  Bi    0.0054644100000001  0.0710383300000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  61  Bi    0.0874316200000000  0.1366121000000000  0.2730790400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  62  Bi    0.0655737700000000  0.8524590200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  63  Bi    0.1475409800000000  0.9180327900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  64  Bi    0.2295082000000000  0.9836065600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  65  Bi    0.0491803300000000  0.6393442600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  66  Bi    0.1311475400000000  0.7049180300000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  67  Bi    0.2131147500000000  0.7704917999999999  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  68  Bi    0.2950819700000000  0.8360655700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  69  Bi    0.3770491800000000  0.9016393400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  70  Bi    0.4590163900000000  0.9672131100000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  71  Bi    0.0327868900000000  0.4262295100000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  72  Bi    0.1147541000000000  0.4918032800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  73  Bi    0.1967213100000000  0.5573770500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  74  Bi    0.2786885200000000  0.6229508200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  75  Bi    0.3606557400000000  0.6885245900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  76  Bi    0.4426229500000000  0.7540983600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  77  Bi    0.5245901600000000  0.8196721300000001  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  78  Bi    0.6065573800000000  0.8852459000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  79  Bi    0.6885245900000000  0.9508196700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  80  Bi    0.0163934400000000  0.2131147500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  81  Bi    0.0983606600000000  0.2786885200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  82  Bi    0.1803278700000000  0.3442623000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  83  Bi    0.2622950800000000  0.4098360700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  84  Bi    0.3442623000000000  0.4754098400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  85  Bi    0.4262295100000000  0.5409836099999999  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  86  Bi    0.5081967200000000  0.6065573800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  87  Bi    0.5901639300000000  0.6721311500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  88  Bi    0.6721311500000000  0.7377049200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  89  Bi    0.7540983600000000  0.8032786900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  90  Bi    0.8360655700000000  0.8688524600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  91  Bi    0.9180327900000000  0.9344262300000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  92  Bi    0.0000000000000000  0.0000000000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  93  Bi    0.0819672100000000  0.0655737700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  94  Bi    0.1639344300000000  0.1311475400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  95  Bi    0.2459016400000000  0.1967213100000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  96  Bi    0.3278688500000000  0.2622950800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  97  Bi    0.4098360700000000  0.3278688500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  98  Bi    0.4918032800000000  0.3934426200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  99  Bi    0.5737704900000000  0.4590163900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  100  Bi    0.6557377000000000  0.5245901600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  101  Bi    0.7377049200000000  0.5901639300000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  102  Bi    0.8196721300000001  0.6557377000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  103  Bi    0.9016393400000000  0.7213114800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  104  Bi    0.9836065600000000  0.7868852500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  105  Bi    0.3114754100000000  0.0491803300000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  106  Bi    0.3934426200000000  0.1147541000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  107  Bi    0.4754098400000000  0.1803278700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  108  Bi    0.5573770500000000  0.2459016400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  109  Bi    0.6393442600000000  0.3114754100000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  110  Bi    0.7213114800000000  0.3770491800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  111  Bi    0.8032786900000000  0.4426229500000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  112  Bi    0.8852459000000000  0.5081967200000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  113  Bi    0.9672131100000000  0.5737704900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  114  Bi    0.5409836099999999  0.0327868900000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  115  Bi    0.6229508200000000  0.0983606600000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  116  Bi    0.7049180300000000  0.1639344300000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  117  Bi    0.7868852500000000  0.2295082000000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  118  Bi    0.8688524600000000  0.2950819700000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  119  Bi    0.9508196700000000  0.3606557400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  120  Bi    0.7704917999999999  0.0163934400000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  121  Bi    0.8524590200000000  0.0819672100000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  122  Bi    0.9344262300000000  0.1475409800000000  0.3637840400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  123  Bi    0.1584698700000000  0.7814208400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  124  Bi    0.2240436400000000  0.8633880500000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  125  Bi    0.2896174100000000  0.9453552600000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  126  Bi    0.1748633100000000  0.5519126400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  127  Bi    0.2404370800000000  0.6338798500000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  128  Bi    0.3060108500000000  0.7158470700000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  129  Bi    0.3715846200000000  0.7978142800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  130  Bi    0.4371583900000000  0.8797814900000001  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  131  Bi    0.5027321600000000  0.9617487000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  132  Bi    0.1912567500000000  0.3224044400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  133  Bi    0.2568305200000000  0.4043716600000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  134  Bi    0.3224043000000000  0.4863388700000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  135  Bi    0.3879780700000000  0.5683060800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  136  Bi    0.4535518400000000  0.6502733000000001  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  137  Bi    0.5191256100000000  0.7322405100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  138  Bi    0.5846993800000000  0.8142077200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  139  Bi    0.6502731500000000  0.8961749300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  140  Bi    0.7158469200000001  0.9781421500000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  141  Bi    0.1420764300000000  0.0109290300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  142  Bi    0.2076502000000000  0.0928962500000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  143  Bi    0.2732239700000000  0.1748634600000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  144  Bi    0.3387977400000000  0.2568306700000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  145  Bi    0.4043715100000000  0.3387978900000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  146  Bi    0.4699452800000000  0.4207651000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  147  Bi    0.5355190500000000  0.5027323100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  148  Bi    0.6010928200000000  0.5846995200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  149  Bi    0.6666665899999999  0.6666667400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  150  Bi    0.7322403600000000  0.7486339500000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  151  Bi    0.7978141300000000  0.8306011599999999  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  152  Bi    0.8633879000000000  0.9125683800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  153  Bi    0.9289616700000000  0.9945355900000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  154  Bi    0.3551911800000000  0.0273224800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  155  Bi    0.4207649500000000  0.1092896900000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  156  Bi    0.4863387200000000  0.1912569000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  157  Bi    0.5519124900000000  0.2732241100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  158  Bi    0.6174862600000000  0.3551913300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  159  Bi    0.6830600300000000  0.4371585400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  160  Bi    0.7486338000000000  0.5191257500000001  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  161  Bi    0.8142075700000000  0.6010929699999999  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  162  Bi    0.8797813400000000  0.6830601800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  163  Bi    0.9453551100000001  0.7650273900000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  164  Bi    0.0109288900000000  0.8469946100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  165  Bi    0.0765026600000001  0.9289618200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  166  Bi    0.5683059300000000  0.0437159200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  167  Bi    0.6338797000000000  0.1256831300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  168  Bi    0.6994534800000000  0.2076503400000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  169  Bi    0.7650272500000000  0.2896175600000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  170  Bi    0.8306010200000000  0.3715847700000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  171  Bi    0.8961747900000000  0.4535519800000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  172  Bi    0.9617485600000000  0.5355192000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  173  Bi    0.0273223300000001  0.6174864100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  174  Bi    0.0928960999999999  0.6994536200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  175  Bi    0.7814206900000000  0.0601093600000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  176  Bi    0.8469944600000000  0.1420765700000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  177  Bi    0.9125682300000000  0.2240437900000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  178  Bi    0.9781420000000000  0.3060110000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  179  Bi    0.0437157699999999  0.3879782100000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  180  Bi    0.1092895400000000  0.4699454300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  181  Bi    0.9945354400000000  0.0765028000000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  182  Bi    0.0601092100000000  0.1584700200000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  183  Bi    0.1256829800000001  0.2404372300000000  0.5324482400000000    7.5  7.5  0.0  0.0  0.0  0.0  0  
  184  Bi    0.0163934400000000  0.7704917999999999  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  185  Bi    0.0819672100000000  0.8524590200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  186  Bi    0.1475409800000000  0.9344262300000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  187  Bi    0.0327868900000000  0.5409836099999999  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  188  Bi    0.0983606600000000  0.6229508200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  189  Bi    0.1639344300000000  0.7049180300000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  190  Bi    0.2295082000000000  0.7868852500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  191  Bi    0.2950819700000000  0.8688524600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  192  Bi    0.3606557400000000  0.9508196700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  193  Bi    0.0491803300000000  0.3114754100000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  194  Bi    0.1147541000000000  0.3934426200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  195  Bi    0.1803278700000000  0.4754098400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  196  Bi    0.2459016400000000  0.5573770500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  197  Bi    0.3114754100000000  0.6393442600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  198  Bi    0.3770491800000000  0.7213114800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  199  Bi    0.4426229500000000  0.8032786900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  200  Bi    0.5081967200000000  0.8852459000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  201  Bi    0.5737704900000000  0.9672131100000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  202  Bi    0.0000000000000000  0.0000000000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  203  Bi    0.0655737700000000  0.0819672100000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  204  Bi    0.1311475400000000  0.1639344300000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  205  Bi    0.1967213100000000  0.2459016400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  206  Bi    0.2622950800000000  0.3278688500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  207  Bi    0.3278688500000000  0.4098360700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  208  Bi    0.3934426200000000  0.4918032800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  209  Bi    0.4590163900000000  0.5737704900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  210  Bi    0.5245901600000000  0.6557377000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  211  Bi    0.5901639300000000  0.7377049200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  212  Bi    0.6557377000000000  0.8196721300000001  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  213  Bi    0.7213114800000000  0.9016393400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  214  Bi    0.7868852500000000  0.9836065600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  215  Bi    0.2131147500000000  0.0163934400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  216  Bi    0.2786885200000000  0.0983606600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  217  Bi    0.3442623000000000  0.1803278700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  218  Bi    0.4098360700000000  0.2622950800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  219  Bi    0.4754098400000000  0.3442623000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  220  Bi    0.5409836099999999  0.4262295100000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  221  Bi    0.6065573800000000  0.5081967200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  222  Bi    0.6721311500000000  0.5901639300000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  223  Bi    0.7377049200000000  0.6721311500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  224  Bi    0.8032786900000000  0.7540983600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  225  Bi    0.8688524600000000  0.8360655700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  226  Bi    0.9344262300000000  0.9180327900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  227  Bi    0.4262295100000000  0.0327868900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  228  Bi    0.4918032800000000  0.1147541000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  229  Bi    0.5573770500000000  0.1967213100000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  230  Bi    0.6229508200000000  0.2786885200000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  231  Bi    0.6885245900000000  0.3606557400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  232  Bi    0.7540983600000000  0.4426229500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  233  Bi    0.8196721300000001  0.5245901600000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  234  Bi    0.8852459000000000  0.6065573800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  235  Bi    0.9508196700000000  0.6885245900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  236  Bi    0.6393442600000000  0.0491803300000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  237  Bi    0.7049180300000000  0.1311475400000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  238  Bi    0.7704917999999999  0.2131147500000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  239  Bi    0.8360655700000000  0.2950819700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  240  Bi    0.9016393400000000  0.3770491800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  241  Bi    0.9672131100000000  0.4590163900000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  242  Bi    0.8524590200000000  0.0655737700000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  243  Bi    0.9180327900000000  0.1475409800000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
  244  Bi    0.9836065600000000  0.2295082000000000  0.6231532400000001    7.5  7.5  0.0  0.0  0.0  0.0  0  
Atoms.SpeciesAndCoordinates>

Atoms.UnitVectors.Unit            Ang
<Atoms.UnitVectors
  28.3821289999999991 18.9074199999999983 0.0000000000000000
  -2.1832360000000000 34.0333559999999977 0.0000000000000000
  0.0000000000000000 0.0000000000000000 19.0000000000000000
Atoms.UnitVectors>

scf.XcType                        GGA-PBE   # LDA/LSDA-CA/LSDA-PW/GGA-PBE
scf.ElectronicTemperature         300.0     # default=300 (K) SIGMA in VASP
scf.energycutoff                  300       # default=150 (Ry = 13.6eV)
scf.maxIter                       2000
scf.EigenvalueSolver              Band      # DC/DC-LNO/Krylov/ON2/Cluster/Band
scf.Kgrid                         2  2  1
scf.criterion                     4e-08     # (Hartree = 27.21eV)
scf.partialCoreCorrection         on

scf.SpinPolarization              nc
scf.SpinOrbit.Coupling            on

scf.Mixing.Type                   RMM-DIISK
scf.Init.Mixing.Weight            0.3
scf.Mixing.History                30
scf.Mixing.StartPulay             6
scf.Mixing.EveryPulay             1

1DFFT.EnergyCutoff                3600
1DFFT.NumGridK                    900
1DFFT.NumGridR                    900

scf.ProExpn.VNA                   off

MD.Type                           Nomd      # Nomd (SCF) / NVT_NH (MD)

Band.dispersion                 on
Band.Nkpath                     3
<Band.kpath
20 0.666666667 0.333333333 0.000  0.000 0.000 0.000  K \Gamma
20 0.000 0.000 0.000  0.500 0.000 0.000  \Gamma M
15 0.500 0.000 0.000  0.333333333 -0.333333333 0.000  M K'
Band.kpath>
### END ###
"""
with open('../example/work_dir/olp/5_4/openmx_in.dat', 'w') as save_f:
    save_f.write(save_str)
save_str = f"""cd "{os.path.abspath("../example/work_dir/olp/5_4")}"
mkdir output
mpirun -np 16 {openmx_overlap_path} openmx_in.dat > openmx.std
"""
with open('../example/4_compute_overlap/run.sh', 'w') as save_f:
    save_f.write(save_str)

os.makedirs('../example/5_inference', exist_ok=True)
os.makedirs('../example/work_dir/inference/5_4', exist_ok=True)
save_str = f"""[basic]
OLP_dir = {os.path.abspath("../example/work_dir/olp/5_4/")}
work_dir = {os.path.abspath("../example/work_dir/inference/5_4/")}
structure_file_name = POSCAR
task = [1, 2, 3, 4, 5]
sparse_calc_config = {os.path.abspath("../example/work_dir/inference/5_4/band.json")}
trained_model_dir = {os.path.abspath("../example/work_dir/trained_model")}
restore_blocks_py = True

[interpreter]
julia_interpreter = {julia_interpreter}

[graph]
radius = 9.0
create_from_DFT = True
"""
with open('../example/5_inference/inference.ini', 'w') as save_f:
    save_f.write(save_str)
save_str = """{
  "calc_job": "band",
  "which_k": 0,
  "fermi_level": -3.594117550337986,
  "max_iter": 300,
  "num_band": 50,
  "k_data": ["20 0.3333333333333333 0.6666666666666667 0 0 0 0 K Γ", "20 0 0 0 0.5 0.5 0 Γ M", "15 0.5 0.5 0 0.6666666666666667 0.3333333333333333 0 M K'"]
}"""
with open('../example/work_dir/inference/5_4/band.json', 'w') as save_f:
    save_f.write(save_str)
save_str = f"""deeph-inference --config inference.ini
"""
with open('../example/5_inference/run.sh', 'w') as save_f:
    save_f.write(save_str)
